#include "Enemy.hh"
#include <iostream>

Enemy::~Enemy() {
    for (Item* item : inventory) {
        delete item;
    }
}

bool Enemy::takeDamage(unsigned damage) {
    if (damage >= health) {
        health = 0;
        std::cout << name << " has been defeated!\n";
        return true;
    } else {
        health -= damage;
        return false;
    }
}

bool Enemy::attack(ICharacter& target) {
    unsigned damage = attacks;
    int actualDamage = static_cast<int>(damage) - static_cast<int>(target.getDefense());
    if (actualDamage < 0) actualDamage = 0;
    std::cout << name << " attacks " << target.getName()
              << " for " << actualDamage << " damage!\n";
    return target.takeDamage(actualDamage);
}